<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <ul id="box">
        <li>我是第1个</li>
        <li>我是第2个</li>
        <li id="li3">我是第3个</li>
        <li>我是第4个</li>
        <li>我是第5个</li>
    </ul>
    <script>
        // var oLi=document.querySelector("#li3");
        // (oLi.previousElementSibling||oLi.previousSibling).style.backgroundColor="red";
        // (oLi.nextElementSibling||oLi.nextSibling).style.backgroundColor="red";

        // var oBox=document.querySelector("#box");
        // for(var i=0;i<oBox.children.length;i++){
        //     oBox.children[i].style.backgroundColor=(i%2==0)?"yellow":"skyblue";
        // }
        var oBox=document.querySelector("#box");
        var ele=oBox.firstElementChild||oBox.firstChild;
        ele.style.backgroundColor="red";

        var ele2=oBox.lastElementChild||oBox.lastChild;
        ele2.style.backgroundColor="pink";

        oBox.children[2].style.backgroundColor="skyblue";
    </script>
</body>
</html>